package com.icez.demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.icez.demo.databinding.ActivityMainBinding
import com.icez.demo.databinding.ApplicationEmptyLayoutBinding
import com.icez.loadlayoutlibrary.LoadLayout

class MainActivity : AppCompatActivity(), LoadLayout.OnShowLayoutListener {
    var binding:ActivityMainBinding ?= null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.inflate(LayoutInflater.from(this),R.layout.activity_main,null,false)
        setContentView(binding?.root)

        binding?.loadLayout?.mOnShowLayoutListener = this

        binding?.contentBtn?.setOnClickListener {
            binding?.loadLayout?.showContentLayout()
        }

        binding?.emptyBtn?.setOnClickListener {
            binding?.loadLayout?.showEmptyLayout()
        }

        binding?.loadingBtn?.setOnClickListener {
            binding?.loadLayout?.showLoadingLayout()
        }

        binding?.errorBtn?.setOnClickListener {
            binding?.loadLayout?.showErrorLayout()
        }


    }

    override fun showLoadingLayout(mViewDataBinding: ViewDataBinding?) {

    }

    override fun showEmptyLayout(mViewDataBinding: ViewDataBinding?) {
        when(mViewDataBinding){
            is ApplicationEmptyLayoutBinding ->{
                Toast.makeText(this@MainActivity,mViewDataBinding.text.text.toString(),Toast.LENGTH_SHORT).show()
            }
        }
    }

    override fun showErrorLayout(mViewDataBinding: ViewDataBinding?) {

    }

    override fun showCustomLayout(mViewDataBinding: ViewDataBinding?) {

    }
}